#include <iostream>
using namespace std;
const int N = 11;
string a[N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int l1, r1;
int l2, r2;
int ans;
void slove(int x1, int y1, int x2, int y2) {
    int t = 100000000;
    while(t--) {
        if(dx[l1] + x1 > 9 || dx[l1] + x1 < 0 || dy[r1] + y1 > 9 || dy[r1] + y1 < 0 || a[dx[l1] + x1][dy[r1] + y1] == '*') {
            l1 = (l1 + 1) % 4;
            r1 = (r1 + 1) % 4;
        }else if(dx[l1] + x1 <= 9 || dx[l1] + x1 >= 0 || dy[r1] + y1 <= 9 || dy[r1] + y1 >= 0){
            x1 += dx[l1];
            y1 += dy[r1];
        }
        if( dx[l2] + x2 > 9 || dx[l2] + x2 < 0 || dy[r2] + y2 > 9 || dy[r2] + y2 < 0 ||a[dx[l2] + x2][dy[r2] + y2] == '*' ) {
            l2 = (l2 + 1) % 4;
            r2 = (r2 + 1) % 4;
        }else if(dx[l2] + x2 < 10 || dx[l2] + x2 >= 0 || dy[r2] + y2 <= 9 || dy[r2] + y2 >= 0){
            x2 += dx[l2];
            y2 += dy[r2]; 
        }
        ans++;
        if(x1 == x2 && y1 == y2) {
            cout << ans;
            return;
        }
    }
    cout << 0;
}
int main() {
    int x1, y1;
    int x2, y2;
    for(int i = 0; i < 10; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            if(a[i][j] == 'C') {
                x1 = i;
                y1 = j;
            }else if(a[i][j] == 'F') {
                x2 = i;
                y2 = j;
            }
        }
    }
    slove(x1, y1, x2, y2);
    return 0;
}
//优化写法，更加正确
/* 
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;

const int N = 10;
char grid[N][N];
bool visited[N][N][4][N][N][4];
int dx[4] = {-1, 0, 1, 0}; // 北 东 南 西
int dy[4] = {0, 1, 0, -1};

struct State {
    int cx, cy, cdir; // cow position + direction
    int fx, fy, fdir; // farmer position + direction
    int steps;
};

bool is_valid(int x, int y) {
    return x >= 0 && x < N && y >= 0 && y < N && grid[x][y] != '*';
}

State move_one(int x, int y, int dir) {
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (!is_valid(nx, ny)) {
        dir = (dir + 1) % 4; // turn right
        nx = x; ny = y;
    } else {
        x = nx; y = ny;
    }
    return {x, y, dir, 0, 0, 0}; // dummy rest
}

int bfs(int cx, int cy, int fx, int fy) {
    queue<State> q;
    q.push({cx, cy, 0, fx, fy, 0, 0});
    visited[cx][cy][0][fx][fy][0] = true;

    while (!q.empty()) {
        State s = q.front(); q.pop();

        if (s.cx == s.fx && s.cy == s.fy)
            return s.steps;

        // move cow
        int ncx = s.cx + dx[s.cdir];
        int ncy = s.cy + dy[s.cdir];
        int ncdir = s.cdir;
        if (!is_valid(ncx, ncy)) {
            ncx = s.cx; ncy = s.cy;
            ncdir = (s.cdir + 1) % 4;
        }

        // move farmer
        int nfx = s.fx + dx[s.fdir];
        int nfy = s.fy + dy[s.fdir];
        int nfdir = s.fdir;
        if (!is_valid(nfx, nfy)) {
            nfx = s.fx; nfy = s.fy;
            nfdir = (s.fdir + 1) % 4;
        }

        if (!visited[ncx][ncy][ncdir][nfx][nfy][nfdir]) {
            visited[ncx][ncy][ncdir][nfx][nfy][nfdir] = true;
            q.push({ncx, ncy, ncdir, nfx, nfy, nfdir, s.steps + 1});
        }
    }

    return 0; // 无法相遇
}

int main() {
    int cx, cy, fx, fy;
    for (int i = 0; i < N; i++) {
        cin >> grid[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (grid[i][j] == 'C') {
                cx = i; cy = j;
            } else if (grid[i][j] == 'F') {
                fx = i; fy = j;
            }
        }
    }

    cout << bfs(cx, cy, fx, fy) << endl;
    return 0;
}

*/